package stu.ais.HomeWork;



public class Computer {    private String brand;

    private double price;

    //对象与对象之间是存在关系的
    //一个计算机应该维护一个显示器
    //修饰符 数据类型 属性名
    private Screen screen;

    //构造  alter+enter
    public Computer() {
    }

    public Computer(String brand, double price) {
        this.brand = brand;
        //this.price = price;

        //如果某个属性需要校验.. 构造方法中直接调用setter方法
        setPrice(price);
    }

    //getter/setter  alter+enter

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        //针对 价格，不能低于1000, 也不能超过20000;
        //对于超出这个值的，给一个默认值：2000
        if(price<1000 || price>20000){
            this.price = 2000;
            return;//return语句是用来结束整个方法的.下面的代码不会执行了.
        }
        this.price = price;
    }

    public Screen getScreen() {
        return screen;
    }

    public void setScreen(Screen screen) {
        this.screen = screen;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "brand='" + brand + '\'' +
                ", price=" + price +
                ", screen=" + screen +
                '}';
    }
}


